#include "qdisplayterms.h"

QDisplayTerms::QDisplayTerms(QVBoxLayout* layout)
   : m_layout(layout)
{
	m_pool = new QObjectPool<QSearchTerms>(5);
}

QDisplayTerms::~QDisplayTerms()
{
	delete m_pool;
	m_pool = NULL;
}


void QDisplayTerms::setPartToDisplay(QEXPPart* part)
{
	clearLayout();
	if(part)
	{
		QList<QSearchTerms*> terms = QSearchTermsFactory::fromPart(m_pool,part);
		foreach(QSearchTerms* s, terms)
		{
			if(s)
				m_layout->addWidget(s);
		}	
	}
}

void QDisplayTerms::clearLayout()
{
	while(m_layout->count())
	{
		QWidget* widget = m_layout->itemAt(0)->widget();
		widget->disconnect();
		m_layout->removeWidget(widget);
		m_pool->release((QSearchTerms*)widget);
	}
}